<?php

namespace app\admin\controller;
use app\BaseController;
use think\facade\Db;

class Admin extends BaseController {

  public function menu(){
    // 必须请求，用来中间件判断登录
    returnJson(0, '成功！', []);
  }

  public function list() {
    $request = request()->param();

    //分页查询
    $page = pageQuery($request);

    $adminList = Db::table('sys_admin')->order('id', 'asc')->page($page['page'], $page['count'])->select();
    if (!$adminList) {
      returnJson(-2, '查询失败！');
    }
    $adminCount = Db::table('sys_admin')->count(); //总条数

    $data = [
      'page' => $page['page'],
      'count' => $page['count'],
      'total' => $adminCount,
      'rows' => $adminList->toArray(),
    ];

    returnJson(0, '成功！', $data);
  }


  public function updatepassword(){
    $request = request()->param();

    if (!isset($request['id']) || !isset($request['password'])) {
      returnJson(-2, '参数错误！');
    }

    $id = $request['id'];
    $password = $request['password'];

    $update = Db::table('sys_admin')->where('id', $id)->update(['password'=>md5($password) ]);
    if ($update >= 0) {
      returnJson(0, '修改成功！');
    }
    returnJson(-2, '修改失败！');

  }

}



